package com.trippartner.client.menu.presenter;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.web.bindery.event.shared.EventBus;
import com.trippartner.client.menu.event.GlobalMenuCommandEnum;
import com.trippartner.client.menu.event.GlobalMenuCommandHandler;
import com.trippartner.client.menu.event.GlobalMenuEvent;
import com.trippartner.client.pattern.HasCommand;
import com.trippartner.client.pattern.MVPDisplay;
import com.trippartner.client.pattern.MVPPresenter;

public class GlobalMenuPresenter extends MVPPresenter<GlobalMenuPresenter.Display> {

	public interface Display extends MVPDisplay {
		HasCommand getLoadMenuFileItem();

		HasCommand getSaveMenuFileItem();

		HasCommand getQuitMenuFileItem();

		HasCommand getAddGeoPointMenuMapItem();

		HasCommand getDelCurrentPointMenuMapItem();

		HasCommand getDelAllPointsMenuMapItem();

		HasCommand getHelpMenuHelpItem();
		
		/** le menu est extensible en longueur */
		void setWidth(String width);
	}

	public GlobalMenuPresenter(Display display, EventBus eventBus) {
		super(display, eventBus);
	}

	@Override
	public void go(final HasWidgets container) {
		bind();
		container.add(display.asWidget());
	}

	@Override
	protected void registerHandler() {
		display.getLoadMenuFileItem().setCommandHandler(new GlobalMenuCommandHandler() {
			// pour avoir un event sur le bus. (gestion de l'historique au
			// niveau global, log, etc...
			public void onGlobalMenuCommandAction(GlobalMenuEvent event) {
				eventBus.fireEvent(new GlobalMenuEvent(GlobalMenuCommandEnum.OUVRIR));
			}

			public void execute() {
				Window.alert("coucou");
			}
		});
		/*
		eventBus.addHandler(ResizeEvent.getType(), new ResizeHandler() {
			public void onResize(ResizeEvent event) {
				display.setWidth(event.getWidth()+"px");
			}
		});*/
	}
	
	@Override
	protected void bind() {
	}

}
